package top.deepdesigner.controller.user;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.deepdesigner.annotation.RequiresPermissionsDesc;
import top.deepdesigner.pojo.DtsFeedback;
import top.deepdesigner.service.DtsFeedbackService;
import top.deepdesigner.util.ResponseUtil;
import top.deepdesigner.vo.CommonListVO;

import java.util.HashMap;
import java.util.List;

/**
 * Start up <br/>
 * Created with IntelliJ IDEA. <br/>
 * Project Name: shop_manage <br/>
 * Author: duanruiqing <br/>
 * DateTime: 2022/9/22 星期四 22:08:00 <br/>
 */
@RestController
@CrossOrigin
@RequestMapping("/admin/feedback")
public class FeedBackController {
  @Autowired
  private DtsFeedbackService feedbackService;

  //获取意见反馈列表
  @RequiresPermissionsDesc(menu = {"用户管理", "意见反馈"}, button = "获取列表")
  @RequiresPermissions(value = {"admin:feedback:list"})
  @GetMapping("/list")
  public Object list(
      @RequestParam HashMap<String, Object> params,
      @RequestParam(defaultValue = "") Integer id,
      @RequestParam(defaultValue = "") String username) {
    Integer page = Integer.parseInt((String) params.get("page"));
    Integer limit = Integer.parseInt((String) params.get("limit"));
    String sort = (String) params.get("sort");
    String order = (String) params.get("order");

    CommonListVO<DtsFeedback> feedbackListVO = new CommonListVO<>();
    //获取数量
    Long count = feedbackService.getFeedbackCount();
    List<DtsFeedback> dtsDtsFeedback = feedbackService.getFeedbackList(page, limit, sort, order, id, username);
    feedbackListVO.setTotal(count);
    feedbackListVO.setItems(dtsDtsFeedback);
    return ResponseUtil.ok(feedbackListVO);
  }
}
